<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8" >
    <!--移动端更好的适应-->
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" th:href="@{/dist/semantic/semantic.min.css}">
    <link rel="stylesheet" th:href="@{/lib/editormd/css/editormd.min.css}">
    <link rel="stylesheet" th:href="@{/css/my.css}">
    <title>博客修改</title>
</head>

<body>
    <!--导航开始--------------------------------------------->
    <nav class="ui inverted attached segment m-padded-mini m-shadow-small" >
        <div class="ui container">
            <div class="ui inverted secondary stackable menu">
                <h2 class="ui teal header item">管理后台</h2>
                <a th:href="@{/admin/findBlog}" class="m-item item m-mobile-hide" th:classappend="${n==1} ? 'active'"><i class="home icon"></i>博客</a>
                <a th:href="@{/admin/type}" class="m-item item m-mobile-hide" th:classappend="${n==2} ? 'active'"><i class="idea icon"></i>分类</a>
                <a th:href="@{/admin/tags}" class="m-item item m-mobile-hide" th:classappend="${n==3} ? 'active'"><i class="tags icon"></i>标签</a>
                <div class="right m-item m-mobile-hide menu">
                    <div class="ui dropdown item">
                        <img class="ui avatar image" th:src="@{/images/me.jpg}">QIUYANG
                        <i class="dropdown icon"></i>
                        <div class="menu">
                            <a href="#" class="item">修改密码</a>
                            <a href="#" class="item">个人信息</a>
                            <a href="#" class="item">注销</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <a href="#" class="ui m-menu m-toggle black icon button m-right-top m-mobile-show">
            <i class="sidebar icon"></i>
        </a>
    </nav>
    <!-- 二级导航 -->

    <!--导航结束---------------------------------------------->


    <!--中间内容开始------------------------------------------>
    <div class="asd m-padded-large touming">
        <div class="ui container">
            <form  id="formupdate" method="post" class="ui form">
                <input type="hidden" name="id" id="id" th:value="${blogs.id}">
                <div class="required field">
                    <div class="ui left labeled input">
                        <div class="ui selection compact teal basic dropdown label">
                            <input type="hidden"  id="flag" name="flag" th:value="${blogs.flag}">
                            <i class="dropdown icon"></i>
                            <div class="text">原创</div>
                            <div class="menu">
                                <div class="item" data-value="原创">原创</div>
                                <div class="item" data-value="转载">转载</div>
                                <div class="item" data-value="翻译">翻译</div>
                            </div>
                        </div>
                        <input type="text" id="title" name="title" placeholder="标题" th:value="${blogs.title}">
                    </div>
                </div>

                <div class="field">
                <div id="md-content" style="z-index: 1 !important">
                        <textarea placeholder="博客内容" id="context" name="context" th:text="${blogs.context}" style="display: none;">
                            [toc]
                            ## text
                            - java
                            - spring
                            ---
                        </textarea>
                </div>
            </div>


                <div class="two fields">
                    <div class="field">
                        <div class="ui left labeled action input">
                            <label class="ui compact teal basic label">分类</label>
                            <div class="ui fluid selection dropdown">
                                <input type="hidden" id="typeId" name="typeId" th:value="${blogs.getTypeId()}">
                                <i class="dropdown icon"></i>
                                <div class="default text">分类</div>
                                <div class="menu" >
                                    <div th:each="type: ${type}" class="item" th:data-value="${type.id}" th:text="${type.name}"></div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="field">
                        <div class="ui left labeled action input">
                            <label class="ui compact teal basic label">标签</label>
                            <div class="ui fluid selection multiple search dropdown">
                                <input type="hidden" id="tagsId" name="tagsId" th:value="${blogtags}">
                                <i class="dropdown icon"></i>
                                <div class="default text">标签1</div>
                                <div class="menu" >
                                    <div class="item" th:each="tag:${tag}" th:data-value="${tag.id}" th:text="${tag.name}">java</div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="field">
                    <div class="ui left labeled input">
                        <label class="ui teal basic label">首图</label>
                        <input type="text" th:value="${blogs.firstPicture}" id="firstPicture" name="firstPicture" placeholder="首图引用地址">
                    </div>
                </div>

                <div class="inline fields">
                    <div class="field">
                        <div class="ui checkbox">
                            <input type="checkbox" checked th:checked="*{blogs.recommend}" id="recommend" name="recommend" class="hidden">
                            <label for="recommend">推荐</label>
                        </div>
                    </div>
                </div>

                <div class="ui error message"></div>

                <div class="ui right aligned container">
                    <button type="button" class="ui button" onclick="window.history.go(-1)">返回</button>
                    <button type="button" id="save" class="ui secondary button">保存</button>
                    <button type="button" id="public" class="ui teal button" >发布</button>
                </div>

            </form>
        </div>
    </div>
    <!--中间内容结束------------------------------------------>
    <br>
    <!--底部内容开始-->

    <!--底部内容结束------------------------------------------>


<script th:src="@{/dist/jquery/jquery-3.4.1.min.js}"></script>
<script th:src="@{/dist/semantic/semantic.min.js}"></script>
<script th:src="@{/lib/editormd/editormd.min.js}"></script>

    <script>
        $('#public').on('click',function () {
            var formupdate = $('#formupdate').serialize();
            console.log("-----------------"+formupdate);
            $.ajax({
                url:'/admin/updateBlog/1',
                type:'post',
                data:formupdate,
                dataType:'text',
                success:function (data) {
                    window.alert(data);
                    if (data=="修改成功！"){
                        location.href='/admin/findBlog';
                    }
                }
            })
        })
        $('#save').on('click',function () {
            var formupdate = $('#formupdate').serialize();
            console.log("-----------------"+formupdate);
            $.ajax({
                url:'/admin/updateBlog/0',
                type:'post',
                data:formupdate,
                dataType:'text',
                success:function (data) {
                    window.alert(data);
                    if (data=="修改成功！"){
                        location.href='/admin/findBlog';
                    }
                }
            })
        })
    </script>







<script>

    /** 初始化editormd **/
    var contentEditor;
    $(function() {
        contentEditor = editormd("md-content", {
            width: "100%",
            height: 640,
            syncScrolling : "single",
            path: "/lib/editormd/lib/"
        });
    });


    $('.m-menu.m-toggle').click(function () {
        $('.m-item').toggleClass('m-mobile-hide');
    });

    $('.ui.dropdown').dropdown({
        on : 'hover'
    });

    /*-- 表单验证 --*/
    $('.ui.form').form({
        fields : {
            title : {
                identifier: 'title',
                rules: [{
                    type : 'empty',
                    prompt : '标题：请博客标题'
                }]
            }
        }
    });
</script>
</body>
</html>